package com.yangchao.controller;

import org.springframework.http.codec.multipart.FilePart;
import org.springframework.http.codec.multipart.Part;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

class MyForm {
	private String name;
	private MultipartFile file;
	// ...
}

@Controller
public class FileUploadController {

	@PostMapping("/form")
	public String handleFormUpload(MyForm form, BindingResult errors) {
		// ...
		return "ok";
	}

	@PostMapping("/")
	public String handle(@RequestPart("meta-data") Part metadata,
						 @RequestPart("file-data") FilePart file) {
		// ...
		return "ok";
	}

}